package blackithei.UDP;

import java.io.IOException;
import java.net.*;
import java.util.Scanner;

//UDP 单播
//顾客
public class ClientDemo1 {
    public static void main(String[] args) throws IOException {
        //创建键盘录入对象
        Scanner sc=new Scanner(System.in);
        //寻找码头 有随机的端口来传信
        DatagramSocket ds=new DatagramSocket();
        while (true) {
            //创建包裹
            String s=sc.nextLine();
            if("拜拜".equals(s)){
                break;
            }
            byte[] bytes = s.getBytes();

            DatagramPacket dp=new DatagramPacket(bytes,bytes.length, InetAddress.getByName("127.0.0.1"),10001);
            //发送包裹
            ds.send(dp);
        }
        //释放资源
        ds.close();
    }
}
